<?php

declare(strict_types=1);

namespace App\CustHub\Listener;

use App\CustHub\Event\RoomActiveRoom;
use App\CustHub\Service\ChRoomActiveRoomService;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use Psr\Container\ContainerInterface;

#[Listener]
class RoomActiveRoomListener implements ListenerInterface
{
    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function listen(): array
    {
        return [
            RoomActiveRoom::class,
        ];
    }

    public function process(object $event): void
    {
        $schemeIds = $event->schemeIds;
        $robotIds = $event->robotIds;
        $type = $event->type;
        $isSave = $event->isSave;
        if($isSave){
            $this->container->get(ChRoomActiveRoomService::class)->saveHandle($schemeIds, $robotIds, $type);
        }else{
            $this->container->get(ChRoomActiveRoomService::class)->deleteHandle($schemeIds, $robotIds, $type);
        }
    }

}